import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
}
export function login(data: LoginData) {
  return axios.post<LoginRes>('/admin/admin/login', data);
}

export function logout() {
  return axios.post<LoginRes>('/admin/admin/logout');
}

export function getUserInfo() {
  return axios.post<UserState>('/admin/admin/info');
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/admin/admin/menu');
}

export interface AdminListParams {
  current: number;
  pageSize: number;
}

export interface AdminListItem {
  id: number;
  username: string;
  status: number;
  created_at: string;
  updated_at: string;
}

export interface AdminListRes {
  list: AdminListItem[];
  total: number;
}

export function getAdminList(params: AdminListParams) {
  return axios.get<AdminListRes>('/admin/admin/index', { params });
}

export function submitForm(data: any) {
  return axios.post<AdminListRes>('/admin/admin/submit', data);
}